/*
 * Copyright (c) OSGi Alliance (2005). All Rights Reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this
 * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html.
 *
 * This copyright applies to the comments and public final static String fields only
 */
package org.osgi.core.framework.exceptions
{

	/**
	 * A Framework exception used to indicate that a bundle lifecycle problem
	 * occurred.
	 *
	 * <p>
	 * <code>BundleException</code> object is created by the Framework to denote
	 * an exception condition in the lifecycle of a bundle.
	 * <code>BundleException</code>s should not be created by bundle developers.
	 *
	 * <p>
	 * This exception is updated to conform to the general purpose exception
	 * chaining mechanism.
	 *
	 * @version $Revision: 1.14 $
	 */
	public class BundleException extends Error
	{
		private static var serialVersionUID:Number=3571095144220455665;
		/**
		 * Nested exception.
		 */
		private var cause:Error;

		/**
		 * Creates a <code>BundleException</code> that wraps another exception.
		 *
		 * @param msg The associated message.
		 * @param cause The cause of this exception.
		 */
		public function BundleException(msg:String, cause:Error=null)
		{
			super(msg);
			this.cause=cause;
		}

		/**
		 * Returns any nested exceptions included in this exception.
		 *
		 * <p>
		 * This method predates the general purpose exception chaining mechanism.
		 * The {@link #getCause()} method is now the preferred means of obtaining
		 * this information.
		 *
		 * @return The nested exception; <code>null</code> if there is no nested
		 *         exception.
		 */
		public function getNestedException():Error
		{
			return cause;
		}

		/**
		 * Returns the cause of this exception or <code>null</code> if no cause
		 * was specified when this exception was created.
		 *
		 * @return The cause of this exception or <code>null</code> if no cause
		 *         was specified.
		 * @since 1.3
		 */
		public function getCause():Error
		{
			return cause;
		}

		/**
		 * The cause of this exception can only be set when constructed.
		 *
		 * @param cause Cause of the exception.
		 * @return This object.
		 * @throws java.lang.IllegalStateException This method will always throw an
		 *         <code>IllegalStateException</code> since the cause of this
		 *         exception can only be set when constructed.
		 * @since 1.3
		 */
		public function initCause(cause:Error):Error
		{
			throw new Error("IllegalStateException");
		}
	}
}